package classes;

import javax.swing.ImageIcon;

import utils.Date;
import business.AddressBusiness;
import business.ClassroomBusiness;
import exceptions.RepositoryException;

public class Member extends Storable implements Tableble
{
	private String		name;
	private Gender		gender;
	private Date		birth;
	private String		phone;
	private String		eMail;
	private boolean		comungant;
	private int			addressId;
	private int			classroomId;
	private ImageIcon	photo;

	private ClassroomBusiness 	classroomBusiness;
	private AddressBusiness 	addressBusiness;
	
	public Member( String name, Gender gender, Date birth, int addressId, String phone, String eMail, boolean comungat, int classroomId )
	{
		this.setName( name );
		this.setGender( gender );
		this.setBirth( birth );
		this.setPhone( phone );
		this.setEMail( eMail );
		this.setComungant( comungat );
		this.setAddressId( addressId );
		this.setClassroomId( classroomId );
		
		try
		{
			this.classroomBusiness = new ClassroomBusiness();
			this.addressBusiness = new AddressBusiness();
		}
		catch ( RepositoryException e ) {}
	}

	public int getAddressId()
	{
		return addressId;
	}

	public Date getBirth()
	{
		return birth;
	}
	
	public int getClassroomId()
	{
		return classroomId;
	}

	public String getEMail()
	{
		return eMail;
	}

	public Gender getGender()
	{
		return gender;
	}

	public String getName()
	{
		return name;
	}

	public String getPhone()
	{
		return phone;
	}

	public ImageIcon getPhoto()
	{
		return photo;
	}
	
	public boolean equals( Object object )
	{
		boolean ret;
		
		ret = object instanceof Member && ( ( Member ) object ).getId() == this.getId();
		
		return ret;
	}

	public boolean isComungant()
	{
		return comungant;
	}

	public void setAddressId( int addressId )
	{
		this.addressId = addressId;
	}

	public void setBirth( Date birth )
	{
		this.birth = birth;
	}
	
	public void setClassroomId( int classroomId )
	{
		this.classroomId = classroomId;
	}

	public void setComungant( boolean comungant )
	{
		this.comungant = comungant;
	}

	public void setEMail( String mail )
	{
		eMail = mail;
	}

	public void setGender( Gender gender )
	{
		this.gender = gender;
	}

	public void setName( String name )
	{
		this.name = name;
	}

	public void setPhone( String phone )
	{
		this.phone = phone;
	}

	public void setPhoto( ImageIcon photo )
	{
		this.photo = photo;
	}

	@Override
	public String toString()
	{
		String ret;

		ret = this.getName();

		return ret;
	}

	@Override
	public String[] getHead()
	{
		String[] ret;
		
		ret = new String[] { "Id", "Nome", "Sexo", "Nascimento", "Telefone", "e-Mail", "Comungante", "EnderecoId", "SalaId" };
		
		return ret;
	}

	@Override
	public Object[] getRow()
	{
		Object[] ret;
		
		Address address = null;
		Classroom classroom = null;
		try
		{
			address = addressBusiness.get( this.addressId );
			classroom = classroomBusiness.get( this.classroomId );
		}
		catch ( RepositoryException e ) {}
		
		ret = new Object[] { String.valueOf( this.getId() ), this.name, this.gender, this.birth, this.phone, this.eMail, this.comungant, address, classroom };
		
		return ret;
	}
}
